package com.lhj.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lhj.reggie.common.R;
import com.lhj.reggie.dto.DishDto;
import com.lhj.reggie.dto.SetmealDto;
import com.lhj.reggie.entity.Setmeal;
import com.lhj.reggie.service.SetmealDishService;
import com.lhj.reggie.service.SetmealService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.print.DocFlavor;
import java.util.List;

/**
 * 套餐管理
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Resource
    private SetmealService setmealService;

    @Resource
    private SetmealDishService setmealDishService;

    /**
     * 新增套餐
     *
     * @param setmealDto
     * @return
     */
    @PostMapping
    public R<String> save(@RequestBody SetmealDto setmealDto) {
        return setmealService.save(setmealDto);
    }

    /**\
     *
     * 分页查询
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/page")
    public R<Page> page(int page,int pageSize,String name){
        return setmealService.page(page,pageSize,name);
    }

    /**
     * 根据id查询套餐信息和对应菜品
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R<SetmealDto> get(@PathVariable Long id){
        SetmealDto setmealDto = setmealService.getbyIdWithDish(id);
        return R.success(setmealDto);
    }

    /**
     * 修改套餐
     * @param setmealDto
     * @return
     */
    @PutMapping
    public R<String> update(@RequestBody SetmealDto setmealDto){
        return setmealService.update(setmealDto);
    }

    /**
     * (批量)删除套餐
     * @param ids
     * @return
     */
    @DeleteMapping
    public R<String> delete(@RequestParam List<Long> ids){
        return setmealService.delete(ids);
    }

    /**
     * 根据id(批量)停售/起售套餐
     * @param status
     * @param ids
     * @return
     */
    @PostMapping("/status/{status}")
    public R<String> updateStatus(@PathVariable Integer status,Long[] ids){
          return setmealService.updateStatus(status,ids);
    }

    /**
     * 根据条件查询套餐信息
     * @param setmeal
     * @return
     */
    @GetMapping("/list")
    public R<List<Setmeal>> list(Setmeal setmeal){
        return setmealService.list(setmeal);
    }
}
